﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    public class TreeNode
    {
        public int val;
        public TreeNode left;
        public TreeNode right;
        public TreeNode(int val = 0, TreeNode left = null, TreeNode right = null)
        {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public class Tree
    {
        private TreeNode root;

        public Tree(int rootVal) 
        {
            this.root.val = rootVal;
        }
        public bool Compare(Tree oTree)
        {
            if (root == null && oTree.root == null)
            {
                return true;
            }
            
            if (root == null || oTree.root == null)
            { 
                return false;
            }

            return root.val == oTree.root.val
                && CompareNode(root.left, oTree.root.left)
                && CompareNode(root.right, oTree.root.right);
        }
        private bool CompareNode(TreeNode node1, TreeNode node2)
        {
            if (node1 == null && node2 == null)
            {
                return true;
            }

            if (node1 == null || node2 == null)
            {
                return false;
            }

            return (node1.val == node2.val) 
                && CompareNode(node1.left, node2.left)
                && CompareNode(node1.right, node2.right);
        }

        
    }
}
